package com.wuyong.chapter11;

import com.wuyong.Chapter3.Queue;

import java.util.Random;

public class Main {


    public static void main(String[] args) {
        int size = 10000;
        int opNum = 1000000;
        UnionFind1 unionFind1 = new UnionFind1(size);
        System.out.println("args = [" + test(unionFind1, opNum) + "]");

        UnionFind2 unionFind2 = new UnionFind2(size);
        System.out.println("args = [" + test(unionFind2, opNum) + "]");

        UnionFind3 unionFind3 = new UnionFind3(size);
        System.out.println("args = [" + test(unionFind3, opNum) + "]");

    }

    public static  double test(UF uf, long opNumber) {
        long startTime = System.nanoTime();
        Random random = new Random();
        for (int i = 0; i < opNumber; i++) {
            uf.unionElements(random.nextInt(uf.getSize()), random.nextInt(uf.getSize()));
        }
        for (int i = 0; i < opNumber; i++) {
            uf.isConnected(random.nextInt(uf.getSize()), random.nextInt(uf.getSize()));
        }

        long endTime = System.nanoTime();
        return (endTime - startTime) / 1000000000.0;
    }
}
